# Contributor: Marian <marian.buschsieweke@ovgu.de>
# Maintainer: Marian <marian.buschsieweke@ovgu.de>
pkgname=afl++
pkgver=4.01c
pkgrel=0
pkgdesc="Fuzzer relying on genetic algorithms instead of brute force"
url="https://aflplus.plus/"
# s390x: blocked by missing lld
# x86: basic unit tests fails
arch="all !s390x !x86"
license="Apache-2.0"
# afl-cmin requires stat
depends="
	clang
	lld
	llvm
	python3
	"
makedepends="
	clang-dev
	gmp-dev
	grep
	llvm-dev
	python3-dev
	"
checkdepends="
	bash
	cmocka-dev
	"
subpackages="$pkgname-doc"
provides="
	afl=$pkgver-r$pkgrel
	afl-clang=$pkgver-r$pkgrel
	afl-gcc=$pkgver-r$pkgrel
	"
source="
	$pkgname-$pkgver.tar.gz::https://github.com/AFLplusplus/AFLplusplus/archive/refs/tags/$pkgver.tar.gz

	0001-fix-missing-max-path-define.patch
	0002-fix-bin-dir.patch
	0003-fix-wrong-format-specifier.patch
	0004-busybox-stat.patch
	"
builddir="$srcdir/AFLplusplus-$pkgver"

build() {
	# AFL++ is expecting clang, clang++ and ld.lld in LLVM_BINDIR,
	# which is set to `llvm-config --bindir` by default, which points
	# to /usr/lib/llvm13/bin rather than /usr/bin
	export LLVM_BINDIR=/usr/bin
	make AFL_NO_X86=1 LLVM_LTO=1 PREFIX=/usr all
}

check() {
	make AFL_NO_X86=1 test
}

package() {
	make AFL_NO_X86=1 PREFIX=/usr DESTDIR="$pkgdir" install

	# Test cases contain x86 binaries that cause trouble with strip on non-x86
	# architectures, so just drop the test cases here.
	rm -rf "$pkgdir"/usr/share/afl/testcases/
}

sha512sums="
d2b03ab4ff9538fe0b52aa3ed4778a6e5657d64d6f0e5f75a99305bad69c5179d6b1c882650f19a884a740577acb73dab7cee3d5c9c7b06ff2326ffeba37d1fe  afl++-4.01c.tar.gz
f12285163797823d820029b7bc4591fa040aac137724611e3643a77fcf49f04f59efb0e2e95863966636299dd92862bc5319d4434d4543289dfb8392dc39b97a  0001-fix-missing-max-path-define.patch
b4f7b81c1ecfdf9b400fc66b8279457feb7fc878e2e3da6653d8b1ae938979bd27f4f0e378df024f61fb12c1350f5faa5f8b1f991f53ae896d029862d8f33c09  0002-fix-bin-dir.patch
29063f71feff74bb7c74d7e11da654d120d76b178532321ee6c40bf766e3a8834cc09458fc0afdade96c2119fb2fbbb5fd8e01ae5df08ea615688872797380e1  0003-fix-wrong-format-specifier.patch
4a00b4c5a494d06896746e5c5dac93f736efa60a51bcc659adec6ec1c928804af6b3f401a41aaf99451ea7c1611607691deea879b41d3b607c1a9fc41aa914f0  0004-busybox-stat.patch
"
